import { _decorator, Component, director, Label, Node } from 'cc';
import { SDKEventDef } from '../../Init/Managers/TaskSDK/SDKEventDef';
import { WebDataProxy } from '../../Init/Managers/TaskSDK/数据代理类/WebDataProxy';
import { CopyMgr } from '../../Init/Managers/TaskSDK/CopyMgr';
import { UISystem } from '../../Init/SystemUI/UISystem';
import { UIEnum } from '../../Init/SystemUI/UIEnum';
const { ccclass, property } = _decorator;

@ccclass('CopyIDCell')
export class CopyIDCell extends Component {
    @property(Label)
    openID: Label = null;
    protected onLoad(): void {
        director.on(SDKEventDef.UPDATE_OPENID_INFO, this.updateOpenID, this)
    }

    private updateOpenID() {
        this.openID.string = WebDataProxy.inst.OpenIDData.m_OpenID;
    }

    start() {
        this.updateOpenID();
    }

    private async copyID() {
        if (WebDataProxy.inst.OpenIDData.m_OpenID) {
            //@ts-ignore
            await ks.setClipboardData({
                data: WebDataProxy.inst.OpenIDData.m_OpenID,
            });
            // let ok = CopyMgr.copyByH5(WebDataProxy.inst.OpenIDData.m_OpenID);
            // if (ok) {
            //     UISystem.showUI(UIEnum.ToastUI, {
            //         tip: "复制成功",
            //     });
            // }
        }
    }
}

